package controle;

import gui.ChatVoxGui;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class IniciaConexaoChatListener extends Thread
{
	private ServerSocket serverSocket;
	private ChatVoxGui chatVoxGui;
	
	public IniciaConexaoChatListener(ChatVoxGui chatVoxGui)
	{
		this.chatVoxGui = chatVoxGui;
	}
	
	public void run()
	{
		try
		{
			this.serverSocket = new ServerSocket(SocketControlConstants.portaConexaoChatWorker);
			
			while(true)
			{
				System.out.println("Esperando contato do Servidor...");
				Socket conexao =  this.serverSocket.accept();
				System.out.println("Recebido conexão do servidor...");
				IniciaConexaoChatHandler iniciaConexaoChatHandler = new IniciaConexaoChatHandler(conexao, this.chatVoxGui);
				iniciaConexaoChatHandler.start();
			}
			
		} catch (IOException e) 
		{
			e.printStackTrace();
		}
	}
}
